package fule.com.webviewdemo.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import fule.com.webviewdemo.R;
import fule.com.webviewdemo.adapter.ViewPagerAdapter;
import fule.com.webviewdemo.fragment.FM_BadyDetail;
import fule.com.webviewdemo.fragment.FM_Know;
import fule.com.webviewdemo.fragment.FM_ProductCase;
import fule.com.webviewdemo.util.GlideImageLoader;

/**
 * 作者： njb
 * 时间： 2018/8/31 0031-下午 3:53
 * 描述：
 * 来源：
 */
public class ShopDetailActivity extends AppCompatActivity {
    @BindView(R.id.shop_banner)
    Banner shopBanner;
    @BindView(R.id.shop_tablayout)
    TabLayout shopTablayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    private List<Fragment> mList;
    private FM_BadyDetail fmBadyDetail = new FM_BadyDetail();
    private FM_ProductCase fmProductCase = new FM_ProductCase();
    private FM_Know fmKnow = new FM_Know();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_shop_detail);
        ButterKnife.bind(this);

        initBanner();
        initFragment();
    }

    /**
     * 初始化轮播广告
     */
    private void initBanner() {
        //本地图片数据（资源文件）
        List<Integer> list = new ArrayList<>();
        list.add(R.mipmap.b1);
        list.add(R.mipmap.b2);
        list.add(R.mipmap.b3);
        shopBanner.setImages(list)
                .setImageLoader(new GlideImageLoader())
                .start();
    }

    private void initFragment() {
        mList = new ArrayList<>();
        mList.add(fmBadyDetail);
        mList.add(fmProductCase);
        mList.add(fmKnow);
        ViewPagerAdapter vpAdapter = new ViewPagerAdapter(getSupportFragmentManager(), mList);
        viewPager.setAdapter(vpAdapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener
                (shopTablayout));
        viewPager.setOffscreenPageLimit(3);
        shopTablayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener
                (viewPager));
    }


}
